package com.example.haoqisystem.controller;

import com.example.haoqisystem.entity.Student;
import com.example.haoqisystem.request.CreateStudentRequest;
import com.example.haoqisystem.request.QueryStudentListRequest;
import com.example.haoqisystem.request.UpdateStudentRequest;
import com.example.haoqisystem.response.BaseResponse;
import com.example.haoqisystem.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "学生Api")
@RequiredArgsConstructor(onConstructor_ ={@Autowired} )
@RequestMapping("/student")
public class StudentController {
    private final StudentService studentService;

    @ApiOperation(value = "学生注册")
    @PostMapping("/register")
    public BaseResponse<Student> register(@RequestBody CreateStudentRequest request){
        return studentService.register(request);
    }

    @ApiOperation(value ="学生登录" )
    @GetMapping("/login")
    public BaseResponse<Student> login(@RequestParam("account") String account
            ,@RequestParam("password") String password){
        return studentService.login(account,password);
    }
    @ApiOperation(value = "查询学生列表")
    @GetMapping("/queryList")
    public BaseResponse<List<Student>> queryList(QueryStudentListRequest request){
        return studentService.queryList(request);
    }

    @ApiOperation(value = "查询学生详情")
    @GetMapping("/detail")
    public BaseResponse<Student> detail(@RequestParam("id") Long id){
        return studentService.detail(id);
    }

    @ApiOperation(value = "编辑学生信息(账号不可更改！)")
    @PutMapping("/update")
    public BaseResponse<Student> update(@RequestBody UpdateStudentRequest request){
        return studentService.update(request);
    }

    @ApiOperation(value = "删除学员")
    @GetMapping("/delete")
    public BaseResponse<String> delete(@RequestParam("id") Long id){
        return studentService.delete(id);
    }
}
